package cn.wolfcode.luowowo.mgrsite.web.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.Region;
import cn.wolfcode.luowowo.article.query.RegionQueryObject;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IRegionService;
import cn.wolfcode.luowowo.common.domain.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/region")
public class RegionController {

    @Reference
    private IRegionService regionService;

    @Reference
    private IDestinationService destinationService;

    /**
     * 区域管理页面
     */
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") RegionQueryObject qo) {

        PageInfo pageInfo = regionService.queryForPageInfo(qo);

        model.addAttribute("pageInfo", pageInfo);

        return "region/list";

    }

    /**
     * 查询层级为3以下的目的地
     * @return 目的地集合
     */
    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(Integer deep) {

        List<Destination> list = destinationService.getDestByDeep(deep);

        return list;

    }

    /**
     * 区域的添加编辑
     * @return  操作结果
     */
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(Region region) {

        AjaxResult ajaxResult = new AjaxResult();

        regionService.saveOrUpdate(region);

        return ajaxResult;

    }

    /**
     * 改变热度
     * @return  操作结果
     */
    @RequestMapping("/changeHotValue")
    @ResponseBody
    public AjaxResult changeHotValue(int hot,Long id) {


        AjaxResult ajaxResult = new AjaxResult();

        regionService.changeHotValue(hot,id);

        return ajaxResult;

    }

    /**
     * 删除指定区域数据
     * @return  操作结果
     */
    @RequestMapping("/delete")
    @ResponseBody
    public AjaxResult delete(Long id) {


        AjaxResult ajaxResult = new AjaxResult();

        regionService.delete(id);

        return ajaxResult;

    }

    /**
     * 查询关联目的地
     */
    @RequestMapping("/getDestByRegionId")
    @ResponseBody
    public Object getDestByRegionId(Long rid) {

        List<Destination> DestList = regionService.getDestByRegionId(rid);

        return DestList;

    }



}
